package prac5;

/**
 * Implements the Cavalry.
 * 
 * @author			Ian Moriarty
 * @author			Menghong Li
 * @modified		Menghong Li (Aug 2011)- - JavaDoc / Indentation / Style 
 *					Menghong Li & Ian Moriarty - Expanded to meet the requirements of Prac 5
 * @since			21th August 2011
 * @input			none
 * @output			only for regression testing
 * @errorHandling	none
 * @knownBugs		none
 */
public class Cavalry extends Fighter {
	private static final int COST = 3;
	private static final int initLife = 4;
	private static final int initExperience = 0;
	
	/**
	 * Implements each cavalry.
	 *
	 * @complexity	best and worst case: O(1)
	 *			
	 */
	public Cavalry() {
		super(initLife, initExperience);
	}
	
	/**
	 * @return		the cost of the unit
	 * @complexity	Best and Worst case: O(1)
	 */
	public static int getCost() {
		return COST;
	}

	/**
	 * @return		the Initial life of the unit
	 * @complexity	Best and Worst case: O(1)
	 */
	public static int getInitlife() {
		return initLife;
	}

	/**
	 * @return		the Initial experience of the unit
	 * @complexity	Best and Worst case: O(1)
	 */
	public static int getInitexperience() {
		return initExperience;
	}
	
	/**
	 * Returns the speed of the unit
	 *
	 * @return      Returns the speed of the unit. 
	 * @complexity	best and worst case: O(1)
	 *			
	 */
	public int getSpeed() {
		return 2;
	}
	
	/**
	 * Returns the amount of damage performed by the unit when it attacks.
	 *
	 * @return      returns the amount of damage performed by the unit when it attacks. 
	 * @complexity	best and worst case: O(1)
	 *			
	 */
	public int attackDamage() {
		return (2 * this.getExperience() + 1);
	}
	
	/**
	 * decreases the life of the unit by the amount lost (if any) after defending from an attack that indicated the amount of damage indicated by damage.
	 *
	 * @param       the amount of damage performed by the unit when it attacks.
	 * @pre			Cannot have negative attack damage
	 * @post		The unit has been updated with the damage, if any, from that round
	 * @complexity	best and worst case: O(1)
	 *			
	 */
	public void defend(int attackDamage) {
		if (attackDamage < 0) {
			System.out.println("Error: Cannot have negative attack damage.");
			return;
		}
		
		if (attackDamage > (this.getExperience() / 2)) {
			this.setLife(this.getLife()-1);
		}
	}
	
	/**
	 * Returns a string indicating the type of unit, its current life and experience.
	 *
	 * @return      Returns a string indicating the type of unit, its current life and experience.
	 * @complexity	best and worst case: O(1)
	 *			
	 */
	public String toString() {
		return ("Cavalry:\n" + "\tLife:\t" + this.getLife() + "\n\tExperience\t" + this.getExperience());
	}
}
